home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / win / whttpd14.zip / SUPPORT / SHUTSRVR / SHUTSRVR.C next >
C/C++ Source or Header  |  1995-01-06  |  2KB  |  86 lines

  1. //tabs=4
  2. //
  3. //        ==========
  4. //        SHUTSRVR.C
  5. //        ==========
  6. //
  7. // Utility to shut down the server cleanly. Used prior to doing a
  8. // "stability reboot".
  9. //
  10. // Author:    Robert B. Denny
  11. //            <rdenny@netcom.com>
  12. //            06-Jan-95
  13. //
  14. // History:
  15. //
  16. // Who               When        What
  17. // ----------------- ---------   ---------------------------------------
  18. // Robert B. Denny   06-Jan-95   Created - First release
  19. //
  20. //----------------------------------------------------------------------
  21.  
  22. #include <windows.h>
  23. #include <stdio.h>
  24.  
  25. #define VERSION "V1.0/06-Jan-95"
  26.  
  27. extern HINSTANCE _hInstance;        // BC4 has this in library
  28.  
  29. HWND hTheWindow;                // Used by WindCatcher() during enumeration
  30.  
  31. BOOL CALLBACK WindCatcher(HWND hWnd, LPARAM lparam);
  32.  
  33. // ====
  34. // MAIN
  35. // ====
  36. main()
  37. {
  38.     FARPROC lpfnEnumWinCB;            // Thunk for enum callback
  39.  
  40.     hTheWindow = NULL;                // Assume failure
  41.  
  42.     lpfnEnumWinCB = MakeProcInstance((FARPROC)WindCatcher, _hInstance);
  43.     EnumWindows(lpfnEnumWinCB, NULL);
  44.     FreeProcInstance(lpfnEnumWinCB);
  45.  
  46.     if(hTheWindow == NULL)            // If we didn't find an httpd running
  47.         return(0);
  48.  
  49.     //
  50.     // Setting wParam = 1 tells the server it is a
  51.     // programmed close. Bypass the "active connections" alert.
  52.     //
  53.     PostMessage(hTheWindow, WM_CLOSE, 1, 0);
  54.  
  55.     return(0);
  56. }
  57.  
  58.  
  59. //------------------------------------------------------------------------
  60. //
  61. // WindCatcher() - Callback function for EnumTaskWindows(). Passes
  62. //                 back a copy of the next window handle.
  63. //
  64. //------------------------------------------------------------------------
  65. #define BUF_LEN 64
  66. #pragma argsused
  67. BOOL CALLBACK _export WindCatcher (HWND hWnd, LPARAM lparam)
  68. {
  69.     char buf[BUF_LEN+1];
  70.     static const char *tgtName = "httpd";
  71.     register int i;
  72.  
  73.     GetWindowText(hWnd, (LPSTR)buf, BUF_LEN);    // Get name
  74.     for(i=0; i < 5; i++)                        // Avoid huge C library
  75.         if(buf[i] != tgtName[i])
  76.             break;
  77.     if(i == 5)
  78.     {                                            // Found it
  79.         hTheWindow = hWnd;
  80.         return(FALSE);
  81.     }
  82.     return(TRUE);                                // Keep going
  83. }
  84.  
  85.  
  86.